import { Column, CreateDateColumn, Entity, Index, JoinTable, ManyToMany, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
import { Tag } from "../../tags/entities/tag.entity";

@Entity()
@Index(['title'])
export class Content {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ nullable: true })
  parentId: number;

  @Column({ nullable: true })
  topLevelId: number;

  @Column({ type: 'varchar', length: 255, comment: '文章标题/分类标题' })
  title: string;

  @Column({ type: 'varchar', length: 255, comment: '文章简介' })
  description: string;

  @Column({ type: 'longtext', comment: '文章内容' })
  content: string;

  @ManyToMany(() => Tag, (tag) => tag.contents)
  @JoinTable({
    name: 'contents_tags',
  })
  tags: Tag[];

  @Column({
    type: 'varchar',
    length: 255,
    nullable: true,
    comment: '文章封面链接',
  })
  cover: string;

  // 区分是文章还是分类 article category
  @Column({ type: 'varchar', length: 10, comment: 'article/category' })
  type: 'article' | 'category'

  // 发布1 草稿2 删除-1
  @Column({ type: 'tinyint', comment: '发布1 草稿2 删除-1' })
  status: number;

  // 排序优先级 越小越前
  @Column({ type: 'int', default: 0, comment: '排序优先级 越小越前' })
  sortOrder: number;

  // 是否置顶
  @Column({ type: 'boolean', default: false, comment: '是否置顶' })
  top: boolean;

  // 文章浏览量
  @Column({ type: 'int', default: 0, comment: '文章浏览量' })
  browse: number;

  // 文章点赞量
  @Column({ type: 'int', default: 0, comment: '文章点赞量' })
  likes: number;

  @Column({ type: 'varchar', length: 32, comment: '作者id' })
  authorId: string;

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;

  @Column({ nullable: true })
  deleteTime: Date;
}
